package com.software.sqlite.api.app.v1.service.impl;
import com.alibaba.fastjson.JSON;
import com.software.sqlite.api.admin.v1.vo.AdminLoginUserVO;
import com.software.sqlite.api.app.v1.service.IAppV1Service;
import com.software.sqlite.common.CommonContant;
import com.software.sqlite.utils.CommonUtils;
import com.software.sqlite.api.app.v1.vo.AppVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@Service
@Slf4j
public class AppV1Service implements IAppV1Service {

    @Resource
    private HttpServletRequest request;
    @Value("${swagger.host}")
    private String basePath;
    @Value("${file.oss}")
    private boolean fileOss;
    @Value("${server.port}")
    private Integer serverPort;


    @Override
    public AdminLoginUserVO login(String userName, String password,String verifyCode, HttpServletRequest request) {
        AdminLoginUserVO loginUser=null;
        try{
            String path = request.getContextPath();
            String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
            if(CommonUtils.isNotBlank(userName) && CommonUtils.isNotBlank(password)){
//                password=SecureUtil.md5(password);

            }else{
                loginUser.setMsg("参数错误");
                return loginUser;
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return loginUser;
    }

    @Override
    public Long getTokenTime(String token) {
        Long result=0L;
        HttpSession session = request.getSession();
        AdminLoginUserVO loginUser = (AdminLoginUserVO) session.getAttribute(CommonContant.APP_LOGIN_SESSION);
        if(loginUser!=null && loginUser.getToken().equals(token))
        {
            result=1L;
        }
        return result;
    }



}
